//Page Object
import {
  formatNum,
  formatTime
} from "../../utils/commont";
import {
  listNav,
  queryNews
} from "../../api/apis"
Page({
  data: {
    navDataArr: [],
    newsList: [],
  },
  //options(Object)
  onLoad: function (options) {
    this.getNavData()
    this.getNewsList()
  },
  // 获取导航数据
  getNavData: function () {
    listNav().then(res => {
      console.log(res);
      this.setData({
        navDataArr: res.data
      })
    })
  },

  // 获取新闻列表
  getNewsList() {
    queryNews({
      limit: 4,
      hot: true
    }).then(res => {
      res.data.forEach(item => {
        item.view_count = formatNum(item.view_count);
        item.publish_date = formatTime(item.publish_date,1)
      })
      this.setData({
        newsList: res.data
      })
    }) 
  },

  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  onPageScroll: function () {

  },
  //item(index,pagePath,text)
  onTabItemTap: function (item) {

  }
});